package ADD_project;
import java.util.Arrays;
import java.util.Comparator;

class Point {
    double x;
    public Point(double x) {
        this.x = x;
    }
}
public class ClosestPairBF {
    // 计算最接近点对的距离
    public static double closestPair(Point[] points) {
        int n = points.length;
        double minDistance = Double.POSITIVE_INFINITY;//将距离先赋值为无穷大


        // 遍历所有点对
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                // 计算点对的距离
                double distance = Math.abs(points[j].x - points[i].x);
                // 更新最小距离
                minDistance = Math.min(minDistance, distance);
            }
        }
        return minDistance;
    }

    public static void main(String[] args) {
        // 创建点集
        Point[] points = {new Point(2), new Point(12), new Point(40),
                new Point(5), new Point(10), new Point(3)};
        // 调用closestPair方法计算最接近点对的距离
        double minDistance = closestPair(points);
        // 输出结果
        System.out.println("The closest pair distance is: " + minDistance);
    }
}
